//
//  HMComposePhotosView.m
//  Gegeda_music_MY
//
//  Created by lanou3g on 15/11/4.
//  Copyright © 2015年 周莹. All rights reserved.
//

#import "HMComposePhotosView.h"
#import "UIView+Extension.h"
@implementation HMComposePhotosView

-(void)addImage:(UIImage *)image{

    UIImageView *imageView = [[UIImageView  alloc] init];
    // 边框没有
    imageView .contentMode = UIViewContentModeScaleAspectFill;
    imageView.clipsToBounds = YES;
    imageView.image = image;
    [self  addSubview:imageView];


}

-(void)layoutSubviews{

    [super  layoutSubviews];
    int count = self.subviews.count;
    //一行的最大列数
    int maxcolsperrow = 4;
    
    //每一个图片的间距
    CGFloat margin = 10;
    
    //每一个图片的宽高
    //(maxcolsperrow +1)*margin) 之间距离
    CGFloat  imageViewW = (self.width -(maxcolsperrow +1)*margin)/maxcolsperrow;
    CGFloat  imageViewH = imageViewW;
    
    for (int i = 0; i < count; i ++) {
        //行号
        int  row = i/maxcolsperrow;
        //列号
        int coi = i%maxcolsperrow;
        
        UIImageView *imageview = self.subviews[i];
        imageview.width = imageViewW;
        imageview.height = imageViewH;
        imageview.y = row*(imageViewH +margin);
        imageview.x = coi *(imageViewW +margin);
        
        
    }
    
}
-(NSArray*)image{

    NSMutableArray  *array = [NSMutableArray  array];
    for (UIImageView  *imageView in  self.subviews ) {
        [array  addObject:imageView.image];
    }

    return array;

}


@end
